package com.maxatime.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.maxatime.common.constant.BusinessContents;
import com.maxatime.pojo.entity.ExamPlanSubjectRelation;
import com.maxatime.pojo.entity.ExamSubject;
import com.maxatime.service.ExamPlanSubjectRelationService;
import com.maxatime.service.ExamSubjectService;
import com.maxatime.util.MyContent;

@Controller
@RequestMapping("/ExamSubject")
public class ExamSubjectController {
	@Autowired
	ExamSubjectService examSubjectService;
	
//	@Autowired
//	ExamPlanSubjectRelationService examPlanSubjectRelationService;///点详情查询
	
	/**
	 * 
	 * @Title: 考试计划   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @param jsonStr
	 * @param: @return      
	 * @return: Map<String,Object>      
	 * @throws   
	 * @author: ssb    
	 * @date:   2024年2月29日 上午9:24:22   
	 * @version V1.0
	 */
	@RequestMapping("/quest")
	@ResponseBody
	public Map<String, Object> quest(@RequestBody String jsonStr){
		JSONObject jsonObj = JSONObject.parseObject(jsonStr);
		String examSubjectName = jsonObj.getString("examSubjectName");
		int pageNum = jsonObj.getIntValue("pageNum");
		int pageSize = jsonObj.getIntValue("pageSize");
		ExamSubject examSubject = new ExamSubject();
		examSubject.setExamSubjectName(examSubjectName);
		examSubject.setPageNum(pageNum);
		examSubject.setPageSize(pageSize);
		Map<String, Object> m = examSubjectService.list(examSubject);
		m.put(BusinessContents.CODE, "0000");
		m.put(BusinessContents.MSG, "交易成功");
		m.put(BusinessContents.DATA, m.get("examSubject1"));
		m.put("pageInfo", m.get("pageInfo"));
		return m;
	}
	@RequestMapping("/del")
	@ResponseBody
	public Map<String, Object> del(@RequestBody String jsonStr){
		JSONObject jsonObj = JSONObject.parseObject(jsonStr);
		int pkId = jsonObj.getInteger("pkId");
		Map<String , Object> m = new HashMap<>();
		examSubjectService.deleteByPrimaryKey(pkId);
		m.put(BusinessContents.CODE, "2222");
		m.put(BusinessContents.MSG, "删除成功");
		return m;
	}
	@RequestMapping("/save")
	@ResponseBody
	public Map<String, Object> save(@RequestBody ExamSubject examSubject){
		Map<String, Object> m = new HashMap<>();
		examSubjectService.insertSelective(examSubject);
		m.put(MyContent.CODE, "1111");
		m.put(MyContent.MSG, "新增成功");
		return m;
	}
	@RequestMapping("/find")
	@ResponseBody
	public Map<String, Object> find(@RequestBody String jsonStr){
		JSONObject jsonObj = JSONObject.parseObject(jsonStr);
		int pkId = jsonObj.getInteger("pkId");
		Map<String, Object> m = new HashMap<>();
		ExamSubject examSubject = examSubjectService.find(pkId);
		m.put(MyContent.CODE, "3333");
		m.put(MyContent.MSG, "反显成功");
		m.put(MyContent.DATA, examSubject);
		return m;
	}
	@RequestMapping("/update")
	@ResponseBody
	public Map<String, Object> update(@RequestBody ExamSubject examSubject){
		Map<String, Object> m = new HashMap<>();
		examSubjectService.updateByPrimaryKeySelective(examSubject);
		m.put(MyContent.CODE, "4444");
		m.put(MyContent.MSG, "修改成功");
		return m;
	}
	//详情查询
//	@RequestMapping("/xqquest")
//	@ResponseBody
//	public Map<String,Object> xqquest(@RequestBody String jsonStr){
//		JSONObject jsonObj = JSONObject.parseObject(jsonStr);
//		int examPlanId = jsonObj.getInteger("examPlanId");
//		Map<String, Object> m =new HashMap<>();
//		List<ExamPlanSubjectRelation> list = examPlanSubjectRelationService.list(examPlanId);
//		
//		m.put(MyContent.CODE, "5555");
//		m.put(MyContent.MSG, "详情查询成功");
//		m.put(MyContent.DATA, list);
//		return m;
//	}
	
}
